package com.wu.controller;/**
 * @author sun
 * @date 2022/3/21 - 0:05
 */

import com.wu.pojo.Mart;
import com.wu.pojo.Notices;
import com.wu.service.MartService;
import com.wu.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @description: TODO
 * @author
 * @date 2022/3/21 0:05
 * @version 1.0
 */
@RestController
@Api(tags="Mart模块")
@CrossOrigin
@RequestMapping("mart")
public class MartController {

    @Autowired
    private MartService martService;
    @PostMapping("/insertMart")
    @ApiOperation(value="增加Mart")
    public R insertMart(@RequestBody Mart mart){
        try {
            martService.insertSelective(mart);
            return R.ok();
        }catch (Exception e){
            e.printStackTrace();
            return R.error();
        }

    }


    @GetMapping("/deleteMart/{id}")
    @ApiOperation(value="删除Mart")
    public R deleteMart(Integer id){
        try {
            martService.deleteByPrimaryKey(id);
            return R.ok();
        }catch (Exception e){
            e.printStackTrace();
            return R.error();
        }
    }

    @PutMapping("/updateMart")
    @ApiOperation(value="更新Mart")
    public R updateMart(@RequestBody Mart mart){
        try {
            martService.updateByPrimaryKeySelective(mart);
            return R.ok();
        }catch (Exception e){
            e.printStackTrace();
            return R.error();
        }
    }

    @GetMapping("/findMart")
    @ApiOperation(value="查询MartList")
    public R findMart(Mart mart){
        try {
            List<Mart> list= martService.findMart(mart);
            return R.ok().data("martList",list);
        }catch (Exception e){
            e.printStackTrace();
            return R.error();
        }
    }

    @GetMapping("/findMartById/{id}")
    @ApiOperation(value="通过id查询Mart")
    public R findMart(Integer id){
        try {
            Mart mart= martService.selectByPrimaryKey(id);
            return R.ok().data("mart",mart);
        }catch (Exception e){
            e.printStackTrace();
            return R.error();
        }
    }
}
